package com.sky.controller.admin;

import com.sky.dto.ArticleUpdateDTO;
import com.sky.dto.CommentPageDTO;
import com.sky.dto.UserCommentDTO;
import com.sky.entity.Article;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ArticleService;
import com.sky.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/comment")
@Tag(name = "评论相关接口")
public class CommentController {

    private final CommentService commentService;

    @Autowired
    public CommentController(CommentService commentService) {
        this.commentService = commentService;

    }

    /**
     * 分页查询所有评论
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询所有评论")
    public Result<PageResult> list( CommentPageDTO commentPageDTO) {
        log.info("分页查询所有评论：{}", commentPageDTO);
        PageResult pageResult =  commentService.list(commentPageDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据评论id删除评论
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除评论")
    public Result delete(@RequestParam Long id) {
        log.info("删除评论：{}", id);

        commentService.deleteComment(id);
        return Result.success();
    }

    /**
     * 统计评论数量
     */
    @GetMapping("/count")
    @Operation(summary = "统计评论数量")
    public Result<Long> count() {
        log.info("统计评论数量");
        Long count = commentService.countComment();
        return Result.success(count);
    }
}
